package butines.core.gui;

import java.awt.Dimension;
import java.awt.Graphics2D;

import butines.core.gui.style.Text;
import butines.core.gui.style.TextShadow;

public class GUILabel extends GUIComponent {

    private Text text;
    private Text textHovered;
    private Text textActived;
    private Text textDisabled;

    private TextShadow textShadow;

    private String label;
    
    public GUILabel(int x, int y, String label) {
        setPosition(x, y);
        this.label = label;
    }

    protected Text getCurrentText() {
        if (!isEnabled()) {
            return (textDisabled == null) ? text : textDisabled;
        } else if (isPressed()) {
            return (textActived == null) ? text : textActived;
        } else if (isHovered()) {
            return (textHovered == null) ? text : textHovered;
        }
        return text;
    }

    @Override
    public void renderComponent(Graphics2D g2d) {
        
        if (textShadow != null) {
            textShadow.draw(g2d, getX(), getY(), label, getWidth(), getHeight());
        }
            
        Text currentText = getCurrentText();
        if (currentText != null) { 
            currentText.draw(g2d, getX(), getY(), label, getWidth(), getHeight());
        }
        
        measuring(currentText);
    }

    private void measuring(Text text) {
        if (text != null && (getWidth() == 0 || getHeight() == 0)) { 
            Dimension size = text.measuring(label);
            setSize(size.width, size.height);
        }
    }
    
    public Text getDefaultText() {
        return text;
    }

    public void setText(Text text) {
        this.text = text;
    }

    public Text getTextHovered() {
        return textHovered;
    }

    public void setTextHovered(Text text) {
        this.textHovered = text;
    }

    public Text getTextActived() {
        return textActived;
    }

    public void setTextActived(Text text) {
        this.textActived = text;
    }

    public Text getTextDisabled() {
        return textDisabled;
    }

    public void setTextDisabled(Text text) {
        this.textDisabled = text;
    }
    
    public String getLabel() {
        return label;
    }

    public void setLabel(String label) {
        this.label = label;
    }

    public TextShadow getTextShadow() {
        return textShadow;
    }

    public void setTextShadow(TextShadow textShadow) {
        this.textShadow = textShadow;
    }

}
